import {defineConfig, loadEnv, ConfigEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'

// https://vitejs.dev/config/

export default defineConfig(({mode}: ConfigEnv) => {
    const env = loadEnv(mode, process.cwd())

    return {
        plugins: [vue()],
        resolve: {
            alias: {
                '@': resolve(__dirname, 'src')
            }
        },
        server: {
            //允许访问IP
            host: '0.0.0.0',
            //应用端口
            port: Number(env.VITE_APP_PORT),
            //运行是否自动打开游览器
            open: true,
            proxy: {
                [env.VITE_APP_BASE_API]: {
                    changeOrigin: true,
                    target: env.VITE_APP_API_URL,
                    rewrite(path) {
                        console.log(path)
                        return path.replace(new RegExp(`^${env.VITE_APP_BASE_API}`), '')
                    },
                }
            }
        }
    }
})

